<?php
class Configure {
    
    static public $app;//当前选择APP
    
	public function __construct() {
		$this->setAppPath();
	}
    
    //配置项目选择规则
	final public function switchApp() {
		if( strpos($_SERVER['HTTP_HOST'], 'admin') !== FALSE ) {
            define('DEFAULT_STATE','admin');
            define('DEFAULT_ACTION','view');
			return 'APP_ADMIN';
		} else {
            define('DEFAULT_STATE','default');
            define('DEFAULT_ACTION','view');
			return 'APP_EXAMPLE';
        }
	}
    
	private function setAppPath() {
		self::$app = @constant($this->switchApp());
        Common::debug(self::$app, 'choose_app');
		$base = PATH_APP . self::$app . '/';   
        if (empty(self::$app) || !is_dir($base)) {
            die($this->switchApp() . ' 项目不存在');
        }                                        //app的基础目录
		$controllerPath = $base . 'controller/';                            //app的controller目录
		$tempaltePath = $base . 'templates/';                               //app的templates目录
        if (PLATFORM == 'sae') {
            $templateCPath = "saemc://smartytpl/" . self::$app . '/templates_c/';           //app的templats_c目录，SAE使用MC
        } else {
		    $templateCPath = PATH_CACHE . self::$app . '/templates_c/';           //app的templats_c目录
            BaseModelCommon::recursiveMkdir($templateCPath);
        }

		define('PATH_APP_CTL', $controllerPath);        //app的controller
		define('PATH_APP_TPL', $tempaltePath);          //app的templates
		define('PATH_APP_TPC', $templateCPath);         //app的templats_c
	}
}
?>